package B刷题.暴力递归.A回溯;

/**
 * @author wei.zhao
 * @description: 剑指 Offer 46.把数字翻译成字符串
 * @date 2022/11/30 14:14
 */
public class Code05_TranslateNum {

    int result = 0;

    /**
     * 并不需要收集结果，所以不用传递当前已经拼接成的字符串
     */
    public int translateNum(int num) {
        String s = num + "";
        char[] chars = s.toCharArray();
        process(chars, 0);
        return result;
    }

    private void process(char[] chars, int i) {
        if (i == chars.length) {
            result++;
            return;
        }
        process(chars, i + 1);
        if (i < chars.length - 1) {
            if (chars[i] == '1') {
                process(chars, i + 2);
            } else if (chars[i] == '2' && chars[i + 1] <= '5')
                process(chars, i + 2);
        }
    }

}
